<?php

namespace Tbf\Bundle\DatabaseBundle\ListQuery\ConditionalExpress;

use Doctrine\ORM\QueryBuilder;

abstract class AbstractConditionalExpress implements ConditionalExpressInterface
{
    protected $place_holder_num;
    protected function handleFieldName(QueryBuilder $qb,$field_name)
    {
        if (strpos($field_name,'.')===false) {
            $field_name = $this->getDefaultAlias($qb).'.'.$field_name;
        }

        return $field_name;
    }
    protected function getDefaultAlias(QueryBuilder $qb)
    {
        $aliases = $qb->getRootAliases();

        return $aliases[0];
    }
    protected function placeHolderValue(QueryBuilder $qb,$value)
    {
        $this->place_holder_num +=1;
        $place_holder_name = 'holder_'.$this->place_holder_num;
        $qb->setParameter($place_holder_name,$value);

        return ':'.$place_holder_name;
    }
}
